#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
const int N=25,M=1e5+10,MOD=998244353;
typedef pair<int,int>PII;
int n,q;
string arr[M];
int out=1;
int pos;
int dist[M][N];
//int dx[] = { 1,1,2,2 };
//int dy[] = { 2,-2,1,-1 };
int dx[] = { -1,-2,-1,-2 };
int dy[] = { -2,-1,2,1 };
bool st[M][N];
void bfs(int a,int b)
{
    memset(dist,0,sizeof dist);
    dist[out][a]=1;
    memset(st,0,sizeof st);
    queue<PII>q;
    q.push({out,a});
    st[out][a]=true;
    while(q.size())
    {
        auto t=q.front();
        q.pop();
        int i=t.first;
        int j=t.second;
        for(int k=0;k<4;k++)
        {
            int x=dx[k]+i;
            int y=dy[k]+j;
            if(x<=pos&&y<=n&&y>=1&&arr[x][y]!='#')
            {
   
                dist[x][y] = (dist[x][y] + dist[i][j]) % MOD;
               // dist[x][y] = dist[i][j] + dist[x][y];
                if (!st[x][y])
                {
                    st[x][y] = true;
                    q.push({ x,y });
                }
                
            }
            //if (x == pos && y == b)
            //    return;
        }
    }
}
int main()
{
    cin>>n>>q;
    while(q--)
    {
        string s;
        cin>>s;
        if(s=="Add")
        {
            pos++;
            //getchar();
            string ss;
            cin>>ss;
            arr[pos]+=" ";
            arr[pos]+=ss;
        }
        else if(s=="Del")
            out++;
        else
        {
            int a,b;
            cin>>a>>b;
            if (arr[out][a] == '#' || arr[pos][b] == '#' || pos == 0)
                cout << 0 << "\n";
            else
            {
                memset(dist, 0, sizeof dist);
              //  bfs(a, b);
                dist[out][a] = 1;
                for (int i = out+1; i <= pos; i++)
                {
                    for (int j = 1; j <= n; j++)
                    {
                        if (i == pos)
                            j = b;
                        for (int k = 0; k < 4; k++)
                        {
                            int x = i + dx[k];
                            int y = j + dy[k];
                            if (x <= pos && y >= 1 && y <= n && arr[x][y] != '#')
                            {
                                dist[i][j] = (dist[x][y] + dist[i][j]) % MOD;
                            }
                        }
                        if (i == pos)
                            break;
                    }
 
                }
                cout<<dist[pos][b]<<"\n";
                //for (int i = out; i <= pos; i++)
                //{
                //    for (int j = 1; j <= n; j++)
                //        cout << dist[i][j] << " ";
                //    cout << "\n";
                //}
            }

        }

    }   
//            for(int i=out;i<=pos;i++)
//            {
//            	cout<<"\n";
//            	cout<<arr[i]<<"\n";
//			}
     return 0;
}
